#!/usr/bin/env python
"""
# -*- coding: utf-8 -*-
# @Time    : 2020/10/8 14:25
# @Author  : AshJo
# @Desc    : 数据共享
# @Filename: data_sharing.py
# @Version : v1.0
"""
# 进程之间可以通过Manager类实现数据共享

from multiprocessing import Process, Manager, Lock


def change_dic(dic, lock):
    with lock:
        dic['count'] -= 1


if __name__ == '__main__':
    m = Manager()
    lock = Lock()
    dic = m.dict({'count': 100})
    p_1 = []
    for i in range(100):
        p = Process(target=change_dic, args=(dic, lock))
        p.start()
        p_1.append(p)
    for p in p_1:
        p.join()
    print(dic)
